package com.hpeu_12.day1231_homework;

/**
 * 第六题、编写Order类，有int型的orderId，String型的orderName，
 * 相应的getter()和setter()方法，两个参数的构造器，
 * 重写父类的equals()方法：public boolean equals(Object obj)，
 * 并判断测试类中创建的两个对象是否相等。
 */
public class DuoTaiTest5 {
    public static void main(String[] args) {
        Order a = new Order(1, "SS");
        Order b = new Order(1, "SS");
        System.out.println(a.equals(b));
        Order a1= new Order(1,"ddd");
        Order b1= new Order(2,"sss");
        System.out.println(a1.equals(b1));
    }
}
class Order{
    int orderId;
    String orderName;

    public int getOrderId() {
        return orderId;
    }

    public void setOrderId(int orderId) {
        this.orderId = orderId;
    }

    public String getOrderName() {
        return orderName;
    }

    public void setOrderName(String orderName) {
        this.orderName = orderName;
    }
    public Order(){

    }
    public Order(int orderId,String orderName){
        this.orderId=orderId;
        this.orderName=orderName;
    }

//    @Override
//    public boolean equals(Object o) {
//        if (this == o) return true;
//        if (o == null || getClass() != o.getClass()) return false;
//        Order order = (Order) o;
//        return orderId == order.orderId &&
//                Objects.equals(orderName, order.orderName);
//    }
    @Override
    public boolean equals(Object obj){
        if(obj==null) return false;
        if(obj instanceof Order){
            Order order = (Order)obj;
            if(this.orderName.equals(order.orderName)){
                if(this.orderId==order.orderId){
                    return true;
                }else
                    return false;
            }else
                return false;
        }else
            return  false;
    }
}